import { isObject } from "is-type-data";

const loopRef = (targetRef, vm) => {
  while (isObject(vm)) {
    console.log(vm);
    if (vm.$refs[targetRef]) {
      return vm;
    } else {
      vm = vm.$parent;
    }
  }
};

export const resetForm = ({}, data, initData) => {
  Object.keys(data).forEach((key) => {
    data[key] = (initData && initData[key]) || null;
  });
};

export function openDialog({ targetRef }, props) {
  const vm = loopRef(targetRef, this);
  if (vm) {
    vm.$refs[targetRef].open();
  }
}
